<template>
    <div>
        <el-table :data="munelist" style="width: 100%;margin-bottom: 1.25rem;" row-key="id" border default-expand-all
            :tree-props="{ children: 'children' }"  class="table">

            <el-table-column prop="id" label="菜单编号" width="100">
            </el-table-column>

            <el-table-column prop="title" label="菜单名称" width="160">
            </el-table-column>

            <el-table-column prop="pid" label="上级菜单" width="100">
            </el-table-column>

            <el-table-column  label="菜单图标">
                <template slot-scope="item">
                    <div>
                        <i :class="item.row.icon"></i>
                    </div>
                </template>
            </el-table-column>

            <el-table-column prop="url" label="菜单地址">
            </el-table-column>

            <el-table-column label="状态">
                <template slot-scope="item">
                    <div>
                        <el-tag type="success" v-if="item.row.status == 1" plain size="medium">启用</el-tag>
                        <el-tag type="danger" v-else plain size="medium">禁用</el-tag>
                    </div>
                </template>
            </el-table-column>

            <el-table-column label="操作">
                <template slot-scope="item">
                    <div>
                        <el-button type="primary" icon="el-icon-edit" size="mini" @click="edit(item.row.id)">编辑</el-button>
                        <el-button type="danger" icon="el-icon-delete" size="mini" @click="del(item.row.id)">删除</el-button>
                    </div>
                </template>

            </el-table-column>
        </el-table>
        <!-- </el-table> -->
    </div>
</template>
<script>
//使用辅助函数进行取值
import { mapGetters, mapActions } from 'vuex';
//引入请求api
import {menudelete} from "../../request/api"
export default {
    data() {
        return {

        }
    },
    methods: {
        ...mapActions({
            // 给menu/ getMEnuListActions重新命名 为getMenuList
            getMenuList: "menu/getMEnuListActions"
        }),
        //删除数据
        del(id) {
            // console.log(id);
            //使用elementUI组建库提供的弹窗进行判断用户点击的是确定还是取消
            this.$confirm('是否永久删除?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                menudelete({id})
                .then((res)=>{
                    // console.log(res);
                    this.$message(res.msg);
                })
                this.$message({
                    type: 'success',
                    message: '删除成功!'
                });
                // 重新调用vuex库中的方法
                this.$store.dispatch("menu/getMEnuListActions")
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            })

        },
        // 编辑数据
        edit(id){
          //首先，点击编辑的时候要吊起弹窗
          this.$emit("edit",id)
        }
    },
    mounted() {
        //页面挂载完成就请求数据调用getmenulistaction方法
        this.getMenuList()


    },
    watch: {},
    computed: {
        ...mapGetters({
            // 重新命名，给我们的vuex仓库的数组
            munelist: "menu/getMenu"
        })
    },
    filters: {},
    components: {


    }
}
</script>
<style scoped>
.table {
    min-width: 66.875rem;
}
</style>